/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.actions.componentes;

import com.mapping.Componentes;
import com.opensymphony.xwork2.ActionSupport;
import static com.opensymphony.xwork2.Action.SUCCESS;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
/**
 *
 * @author Andres
 */
@Namespace(value="/")
@Action(value="eliminarComponente", results={@Result(name="success",location="/GestionComponentes/rEliminarComponente.jsp")})
public class EliminarComponenteAction extends ActionSupport{
    private String id;
    @Override
    public String execute(){
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("inventarios");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();
        Componentes comp = em.getReference(Componentes.class, Integer.parseInt(id));
        em.remove(comp);
        tx.commit();
        em.close();
        return SUCCESS;
    }

    public void setId(String id) {
        this.id = id;
    }
}
